package com.j2009.springbootproject.web;

import com.j2009.springbootproject.entity.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * ClassName: UploadController
 * Description:
 * date: 2021/3/25 16:30
 *
 * @author wuyafeng
 * @version 1.0   softeem.com
 */

@Controller
public class UploadController {

    /**
     * 注意 这里的文件上传 只是一个注解的不同  springboot封装了上传的组件 @RequestPart
     * @param file
     * @return
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping("/upload")
    public ResponseResult upload(@RequestPart("file")MultipartFile file) throws IOException {

         //文件上传
        System.out.println("文件名："+file.getOriginalFilename());
        file.transferTo(new File("e:/myfile/"+file.getOriginalFilename()));
        return new ResponseResult(0,"上传成功");
}
    // springboot设置默认上传大小  ，也可以手动修改


}
